import json
from json import JSONDecodeError

if __name__ == "__main__":
    data = {
        'no': 1,
        'name': "W3CSchool",
        "url": "http://www.w3cschool.cn"
    }

    # 写入文件
    with open("data.json", "w", encoding="utf-8") as output:
        json.dump(data, output)
    # 读取文件
    try:
        inputFile = open("data.json", "r")
        with inputFile:
            data = json.load(inputFile)
            print(data)
    except FileNotFoundError as e:
        print("文件不存在")
        print(e)
    except JSONDecodeError as e:
        print("解析json错误: ", e)
        raise e
